﻿using Castle.DynamicProxy;
using Developer.Core.FrameWork.DynamicMiddlePlatformService.Service;
using System;
using System.Collections.Generic;
using System.Text;

namespace Developer.Core.FrameWork.MicroClients.Proxy
{
    /// <summary>
    /// 微服务代理工厂，创建代理
    /// </summary>
    public class MicroClientProxyFactory
    {
        private readonly IDynamicMiddlePlatformService platformService;
        public MicroClientProxyFactory(IDynamicMiddlePlatformService platformService)
        {
            this.platformService = platformService;
        }

        /// <summary>
        /// 创建接口代理类，实现类
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public object CreateMicroClientProxy(Type type)
        {
            ProxyGenerator generator = new ProxyGenerator();
            object obj = generator.CreateInterfaceProxyWithoutTarget(type, new MicroClientProxy(this.platformService));
            return obj;
        }
    }
}
